package 链表;

import java.util.Deque;
import java.util.LinkedList;
import java.util.concurrent.LinkedBlockingDeque;

public class 回文链表 {
    //使用栈，先进先出
    public boolean isPalindrome(ListNode head) {
        ListNode cur=head;
        Deque<ListNode> nodes = new LinkedList<>();
        while (cur!=null){
            nodes.push(cur);
            cur=cur.next;
        }
        while (head!=null){
            if (head.val!=nodes.pop().val)
                return false;
            head=head.next;
        }
        return true;
    }
}
